package com.yc.demo.d0301;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "GetDataServlet", value = "/GetDataServlet")
public class GetDataServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //获取请求对象中的数据
        final Object data = request.getAttribute("data");
        //获取会话中的数据
        final Object data1 = request.getSession().getAttribute("data");

        final PrintWriter out = response.getWriter();
        out.printf("请求中的数据data ： %s <br>",data);
        out.printf("会话中的数据data ： %s <br>",data1);
        out.printf("会话id ： %s <br>",request.getSession().getId());

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
